package main

import (
	"fmt"
	"github.com/EDDYCJY/go-gin-app/models"
	"github.com/EDDYCJY/go-gin-app/pkg/logging"
	"github.com/EDDYCJY/go-gin-app/pkg/setting"
	"github.com/EDDYCJY/go-gin-app/routers"
	"net/http"
)

func main()  {
	setting.Setup()
	models.Setup()
	logging.Setup()

	r := routers.InitRouter()
	s:=&http.Server{
		Addr : fmt.Sprintf(":%d", setting.ServerSetting.HttpPort),
		Handler: r,
		ReadTimeout: setting.ServerSetting.ReadTimeout,
		WriteTimeout: setting.ServerSetting.WriteTimeout,
		MaxHeaderBytes: 1<<20,
	}
	s.ListenAndServe()

	//not window
	//endless.DefaultReadTimeOut = setting.ServerSetting.ReadTimeout
	//endless.DefaultWriteTimeOut = setting.ServerSetting.WriteTimeout
	//endless.DefaultMaxHeaderBytes = 1 << 20
	//endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
	//
	//s := endless.NewServer(endPoint, routers.InitRouter())
	//
	//s.BeforeBegin = func(add string) {
	//	log.Printf("Actual pid is %d", syscall.Getpid())
	//}
	////s:=&http.Server{
	////	Addr : fmt.Sprintf(":%d", setting.ServerSetting.HttpPort),
	////	Handler: r,
	////	ReadTimeout: setting.ServerSetting.ReadTimeout,
	////	WriteTimeout: setting.ServerSetting.WriteTimeout,
	////	MaxHeaderBytes: 1<<20,
	////}
	//err := s.ListenAndServe()
	//if err !=nil {
	//	log.Printf("Server err: %v", err)
	//}
}
